package com.ruoyi.vehicles.service.impl;

import java.util.List;
import java.util.UUID;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.AliyunOSSUtil;
import com.ruoyi.vehicles.form.AddRecordsForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.vehicles.mapper.AMaintenanceRecordsMapper;
import com.ruoyi.vehicles.domain.AMaintenanceRecords;
import com.ruoyi.vehicles.service.IAMaintenanceRecordsService;
import org.springframework.util.StringUtils;

/**
 * 维护记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-07
 */
@Service
public class AMaintenanceRecordsServiceImpl implements IAMaintenanceRecordsService 
{
    @Autowired
    private AMaintenanceRecordsMapper aMaintenanceRecordsMapper;


    /**
     * 查询维护记录
     * 
     * @param id 维护记录主键
     * @return 维护记录
     */
    @Override
    public AMaintenanceRecords selectAMaintenanceRecordsById(Long id)
    {
        return aMaintenanceRecordsMapper.selectAMaintenanceRecordsById(id);
    }

    /**
     * 查询维护记录列表
     * 
     * @param aMaintenanceRecords 维护记录
     * @return 维护记录
     */
    @Override
    public List<AMaintenanceRecords> selectAMaintenanceRecordsList(AMaintenanceRecords aMaintenanceRecords)
    {
        return aMaintenanceRecordsMapper.selectAMaintenanceRecordsList(aMaintenanceRecords);
    }

    /**
     * 新增维护记录
     * 
     * @param aMaintenanceRecords 维护记录
     * @return 结果
     */
    @Override
    public int insertAMaintenanceRecords(AddRecordsForm aMaintenanceRecords)
    {
        // 上传文件
        String uploadFile = AliyunOSSUtil.uploadFile(aMaintenanceRecords.getFile());
        // 生成雪花ID
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        aMaintenanceRecords.setInvoice(uploadFile);
        aMaintenanceRecords.setMaintenanceRecordsId(String.valueOf(snowflake.nextId()));
        // 保存数据
        return aMaintenanceRecordsMapper.insertAMaintenanceRecords(aMaintenanceRecords);
    }

    /**
     * 修改维护记录
     * 
     * @param aMaintenanceRecords 维护记录
     * @return 结果
     */
    @Override
    public int updateAMaintenanceRecords(AMaintenanceRecords aMaintenanceRecords)
    {
        return aMaintenanceRecordsMapper.updateAMaintenanceRecords(aMaintenanceRecords);
    }

    /**
     * 批量删除维护记录
     * 
     * @param ids 需要删除的维护记录主键
     * @return 结果
     */
    @Override
    public int deleteAMaintenanceRecordsByIds(Long[] ids)
    {
        return aMaintenanceRecordsMapper.deleteAMaintenanceRecordsByIds(ids);
    }

    /**
     * 删除维护记录信息
     * 
     * @param id 维护记录主键
     * @return 结果
     */
    @Override
    public int deleteAMaintenanceRecordsById(Long id)
    {
        return aMaintenanceRecordsMapper.deleteAMaintenanceRecordsById(id);
    }
}
